package edu.java.homework.hw03.ipj07;

/**
 * Palendrom
 * 
 * @author Tsvetan Vasilev
 * 
 */
public class Exer01 {

    public static void main(String[] args) {
	String str1 = "poiop";
	String str2 = "sos";
	String str3 = "pa";
	String str4 = "belimakamileb";
	String str5 = "kasaki";

	System.out.println(" '" + str1 + "'  palendrom  t/f?  "
		+ isPalendrom(str1));
	System.out.println(" '" + str2 + "'  palendrom  t/f?  "
		+ isPalendrom(str2));
	System.out.println(" '" + str3 + "'  palendrom  t/f?  "
		+ isPalendrom(str3));
	System.out.println(" '" + str4 + "'  palendrom  t/f?  "
		+ isPalendrom(str4));
	System.out.println(" '" + str5 + "'  palendrom  t/f?  "
		+ isPalendrom(str5));

    }

    public static boolean isPalendrom(String string) {
	if (string == null) {
	    throw new IllegalArgumentException("Null-pointed string. Error!");
	}
	boolean result=true;
	int length=string.length();
	for(int i=0;i<length/2;i++){
	    char chLeft=string.charAt(i);
	    char chRight=string.charAt(length-1-i);
	    if(chLeft!=chRight){
		result=false;
		break;
	    }
	}
	return result;
	
    }

}
